﻿using Assets.Script.Human.Player.Action;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Assets.Script.Data.Player;
using UnityEngine;

namespace Assets.Script.Human.Player
{
    public partial class PlayerActionManager:MonoBehaviour
    {
        private PlayerBody playerBody;
        private IAction[] actions;
        private IAction currentState;

        public PlayerStateEnum NowState { get; private set; } = PlayerStateEnum.Idle;

        public void Init(PlayerBody playerBody)
        {
            this.playerBody = playerBody;
            actions = new IAction[] { new IdleAction(playerBody), new RunAction(playerBody),new BeAtkAction(playerBody) };
            currentState = actions[0];
        }

        private void Update()
        {
            currentState.OnUpdate();
        }

        private void FixedUpdate()
        {
            currentState.OnFixedUpdate();
        }

        public void ChangeState(int state, object[] o= null)
        {
            currentState.Interrupt();
            currentState = actions[(int)state];
            currentState.OnEnter(ref o);
            NowState = (PlayerStateEnum)state;
        }

        public void ChangeState(PlayerStateEnum state, object[] o = null)
        {
            int s = (int)state;
            ChangeState(s, o);
        }


    }
}
